package 单次撤销;

/**
 * @author 赵希奥
 * @date 2022/4/20 23:30
 * @gitHub https://github.com/CKXGZXA
 * @gitee https://gitee.com/ckxgzxa
 * @description:
 */
public class Client {
    public static void main(String[] args) {
        MementoCaretaker mc = new MementoCaretaker();
        Chessman chess = new Chessman("車", 1, 1);
        display(chess);
        mc.setMemento(chess.save());    // 保存状态
        chess.setY(4);
        display(chess);
        mc.setMemento(chess.save());    // 保存状态
        chess.setX(5);
        display(chess);
        System.out.println("******悔棋******");
        chess.restore(mc.getMemento()); // 恢复状态
        display(chess);
    }

    private static void display(Chessman chess) {
        System.out.println("棋子" + chess.getLabel() + "的位置是：第" + chess.getX() + "行第" + chess.getY() + "列");
    }
}
